export const UserInfoRules = {
  // 表单校验规则
  data () {
    const checkEmail = (rule, value, cb) => {
      const regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
      if (regEmail.test(value)) {
        return cb()
      }
      cb(new Error('请输入合法的邮箱名'))
    }

    const checkPhone = (rule, value, cb) => {
      const regPhone = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
      if (regPhone.test(value)) {
        return cb()
      }
      cb(new Error('请输入合法的手机号'))
    }
    return {
      rules: {
        username: [
          {
            required: true, message: '请输入用户名', trigger: 'blur'
          },
          {
            min: 2, max: 8, message: '用户名长度需要在2-8之间', trigger: 'blur'
          }
        ],
        password: [
          {
            required: true, message: '请输入密码', trigger: 'blur'
          },
          {
            min: 6, max: 15, message: '密码应在6-15之间', trigger: 'blur'
          }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { validator: checkEmail, trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { validator: checkPhone, trigger: 'blur' }
        ],
        roleName: [
          { required: true, message: '请输入角色名', trigger: 'blur' },
          {
            min: 2, max: 10, message: '角色名应在2-10之间', trigger: 'blur'
          }
        ],
        roleDesc: [
          { required: true, message: '请输入角色描述', trigger: 'blur' },
          {
            min: 2, max: 10, message: '描述应在2-10之间', trigger: 'blur'
          }
        ],
        cat_name: [
          { required: true, message: '请输入商品分类名称', trigger: 'blur' },
          {
            min: 2, message: '名称应在至少两位数', trigger: 'blur'
          }
        ],
        attr_name: [{ required: true, message: '请输入参数名称', trigger: 'blur' }],
        // 添加商品的表单校验
        goods_name: [
          { required: true, message: '请输入商品名称', trigger: 'blur' }
        ],
        goods_price: [
          { required: true, message: '请输入商品价格', trigger: 'blur' }
        ],
        goods_weight: [
          { required: true, message: '请输入商品重量', trigger: 'blur' }
        ],
        goods_number: [
          { required: true, message: '请输入商品数量', trigger: 'blur' }
        ],
        goods_cat: [
          { required: true, message: '请选择商品分类', trigger: 'blur' }
        ]
      }
    }
  }
}

export const addressFormRule = {
  data () {
    return {
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      }
    }
  }
}
